<?php

/**
 * BasesearchProfile
 *
 * This class has been created by maxpowel
 *
 * @property integer $user_id
 * @property integer $visits
 * @property integer $gender
 * @property string $uid
 * @property date $birthday
 * @property integer $city_id
 * @property integer $country_id
 * @property sfGuardUser $user
 * @property Doctrine_Collection $interests
 * @property city $city
 * @property country $country
 * @property Doctrine_Collection $Groups
 * @property Doctrine_Collection $blog
 * @property Doctrine_Collection $interest
 * @property Doctrine_Collection $aclProfileGroup
 * @property Doctrine_Collection $aclProfileUser
 *
 * @method integer             getUserId()          Returns the current record's "user_id" value
 * @method integer             getVisits()          Returns the current record's "visits" value
 * @method integer             getGender()          Returns the current record's "gender" value
 * @method string              getUid()             Returns the current record's "uid" value
 * @method date                getBirthday()        Returns the current record's "birthday" value
 * @method integer             getCityId()          Returns the current record's "city_id" value
 * @method integer             getCountryId()       Returns the current record's "country_id" value
 * @method sfGuardUser         getUser()            Returns the current record's "user" value
 * @method Doctrine_Collection getInterests()       Returns the current record's "interests" collection
 * @method city                getCity()            Returns the current record's "city" value
 * @method country             getCountry()         Returns the current record's "country" value
 * @method Doctrine_Collection getGroups()          Returns the current record's "Groups" collection
 * @method Doctrine_Collection getBlog()            Returns the current record's "blog" collection
 * @method Doctrine_Collection getInterest()        Returns the current record's "interest" collection
 * @method Doctrine_Collection getAclProfileGroup() Returns the current record's "aclProfileGroup" collection
 * @method Doctrine_Collection getAclProfileUser()  Returns the current record's "aclProfileUser" collection
 * @method profile             setUserId()          Sets the current record's "user_id" value
 * @method profile             setVisits()          Sets the current record's "visits" value
 * @method profile             setGender()          Sets the current record's "gender" value
 * @method profile             setUid()             Sets the current record's "uid" value
 * @method profile             setBirthday()        Sets the current record's "birthday" value
 * @method profile             setCityId()          Sets the current record's "city_id" value
 * @method profile             setCountryId()       Sets the current record's "country_id" value
 * @method profile             setUser()            Sets the current record's "user" value
 * @method profile             setInterests()       Sets the current record's "interests" collection
 * @method profile             setCity()            Sets the current record's "city" value
 * @method profile             setCountry()         Sets the current record's "country" value
 * @method profile             setGroups()          Sets the current record's "Groups" collection
 * @method profile             setBlog()            Sets the current record's "blog" collection
 * @method profile             setInterest()        Sets the current record's "interest" collection
 * @method profile             setAclProfileGroup() Sets the current record's "aclProfileGroup" collection
 * @method profile             setAclProfileUser()  Sets the current record's "aclProfileUser" collection
 *
 * @package    sfwixet
 * @subpackage model
 * @author     maxpowel
 * @version
 */

/* view
create or replace view search_profile
as
SELECT user_id,gender,uid,birthday,city_id,country_id,town_id FROM profile
 */
abstract class BasesearchProfile extends sfDoctrineRecord
{
        //Because profile is acl protected, we use this view to
        //get some data when doing an user search
    public function setTableDefinition()
    {
        $this->setTableName('search_profile');
        $this->hasColumn('user_id', 'integer', 4, array(
             'type' => 'integer',
             'primary' => true,
             'length' => 4,
             ));

        $this->hasColumn('gender', 'integer', 1, array(
             'type' => 'integer',
             'length' => 1,
             ));
        $this->hasColumn('uid', 'string', 25, array(
             'type' => 'string',
             'unique' => true,
             'length' => 25,
             ));
        $this->hasColumn('birthday', 'date', null, array(
             'type' => 'date',
             ));
        $this->hasColumn('city_id', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             ));
        $this->hasColumn('country_id', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             ));
        $this->hasColumn('town_id', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             ));
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('sfGuardUser as user', array(
             'local' => 'user_id',
             'foreign' => 'id',
             'onDelete' => 'CASCADE'));

        $this->hasMany('interest as interests', array(
             'local' => 'user_id',
             'foreign' => 'profile_id'));

        $this->hasOne('city', array(
             'local' => 'city_id',
             'foreign' => 'city_id',
             'onDelete' => 'SET NULL'));

        $this->hasOne('country', array(
             'local' => 'country_id',
             'foreign' => 'country_id',
             'onDelete' => 'SET NULL'));

       $this->hasOne('city as town', array(
             'local' => 'town_id',
             'foreign' => 'city_id',
             'onDelete' => 'SET NULL'));

       $this->hasMany('place as places', array(
             'refClass' => 'placeUser',
             'local' => 'user_id',
             'foreign' => 'user_id'));

        $this->hasMany('workplace as workplaces', array(
             'refClass' => 'workplaceUser',
             'local' => 'user_id',
             'foreign' => 'user_id'));

        $this->hasMany('school as schools', array(
             'refClass' => 'schoolUser',
             'local' => 'user_id',
             'foreign' => 'user_id'));

        $this->hasMany('city as cityplace', array(
             'refClass' => 'cityUser',
             'local' => 'user_id',
             'foreign' => 'user_id'));

        //No full relation to make searches faster
        $this->hasMany('placeUser', array(
             'local' => 'user_id',
             'foreign' => 'user_id'));
        $this->hasMany('workplaceUser', array(
             'local' => 'user_id',
             'foreign' => 'user_id'));
        $this->hasMany('cityUser', array(
             'local' => 'user_id',
             'foreign' => 'user_id'));
        $this->hasMany('schoolUser', array(
             'local' => 'user_id',
             'foreign' => 'user_id'));


    }
}
